package com.cxj.controller;

import com.cxj.service.AdminService;
import com.cxj.service.BookingService;
import com.cxj.service.YmService;
import com.cxj.vo.*;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Admin")
public class AdminController {
    @Resource
    private AdminService adminService;
    @Resource
    private YmService ymService;
    @Resource
    private BookingService bookingService;

    //用户登录
    @PostMapping("/login")
    public Boolean Login(@RequestParam String userName, @RequestParam String passWord) {
        if (adminService.login(userName, passWord)) {
            return true;
        } else {
            return false;
        }
    }

    //依据名称查询疫苗信息
    @PostMapping("/selectYmByName")
    public SelectByYmNameRes selectByYmNameRes(@RequestParam String ymName) {
        SelectByYmNameRes selectByYmNameRes = ymService.selectByYmName(ymName);
        return selectByYmNameRes;
    }

    //依据用户名称查询预约信息
    @PostMapping("/selectBookingByUserName")
    public ResponseEntity<?> selectBookingByUserName(@RequestParam String bookingName) {
        SelectBookingByUserNameRes res = bookingService.selectBookingByUserName(bookingName);
        if (res == null) {
            // 如果res为空，返回一个字符串消息
            return ResponseEntity.ok("未找到 '" + bookingName + "' 相关的预约信息。");
        } else {
            // 如果res不为空，返回res对象
            return ResponseEntity.ok(res);
        }
    }

    //用户插入预约
    @PostMapping("/userInsertBooking")
    public String userInsertBooking(@RequestBody UserInsertBookingReq userInsertBookingReq){
        Boolean res = bookingService.userInsertBooking(userInsertBookingReq);
        if(res) {
            return "插入成功";
        }else {
            return "插入失败";
        }
    }

    //用户删除预约
    @PostMapping("/userDeleteBooking")
    public String userDeleteBooking(@RequestParam String ymName,@RequestParam String bookingName){
        Boolean res = bookingService.userDeleteBooking(ymName,bookingName);
        if(res){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    //用户更新预约
    @PostMapping("/userUpdateBooking")
    public String userUpdateBooking(@RequestBody UserUpdateBookingReq userUpdateBookingReq){
        Boolean res = bookingService.userUpdateBooking(userUpdateBookingReq);
        if(res){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
    //用户注册
    @PostMapping("/insertNewUser")
    public String insertNewUser(@RequestParam String Name , @RequestParam String passWord , @RequestParam String userName) {
        String res = adminService.insertNewUser(Name,passWord,userName);
        return res;
    }
}
